import React from 'react';
import {connect} from 'react-redux';
class Shoppingcar extends React.Component{
  constructor(props){
    super(props);
    // console.log(this.props)
  }
  render(){
      let items=this.props.shoppingCar
      let total=0;
    return(
      <div>
        <ul>
            {
                items.map((item,index)=>{
                    total+= item.price*item.count
                    return(
                        <li key={item.id}>
                            产品名称：{item.name}
                             价格：{item.price}
                             数量：{item.count}
                             总价：{item.price*item.count}
                        </li>
                    )
                })
            }
        </ul>
        总价:{total}
      </div>
    )
  }
}

function mapStateToProps(state){
    // console.log(state)
    return{
        shoppingCar:state.shoppingCar.items
    }
}
   


export default connect(mapStateToProps,null)(Shoppingcar);